home *** CD-ROM | disk | FTP | other *** search
/ Georgia Wildfire Prevention / Georgia Wildfire Prevention.iso / pc / media / dirs / BackUp / code.cst / 00011_Script_testobj < prev    next >
Text File  |  2002-10-15  |  4KB  |  155 lines

  1. property scores,curnum,totalnum,questions,correct,cscore,alarm,wait_amt,test,next_action
  2.  
  3. on new me
  4.   scores=[#pre:0,#post:0]
  5.   alarm=0
  6.   wait_amt=0
  7.   return(me)
  8. end
  9.  
  10. on init me
  11.   global ctrlobj
  12.   curnum=0
  13.   questions=[:]
  14.   read_questions(me)
  15.   totalnum=questions.count
  16.   correct=0
  17.   c=ctrlobj.history.count
  18.   test=ctrlobj.history[c].aux
  19.   if test="post" then
  20.     wait_amt=180
  21.   else
  22.     wait_amt=0
  23.   end if
  24. end
  25.  
  26. on read_questions me
  27.   x=1
  28.   correct=0
  29.   cscore=0
  30.   mem=member("question"&string(x))
  31.   repeat while mem.number>0
  32.     str=mem.text
  33.     qlist=[]
  34.     repeat with i=1 to str.lines.count
  35.       qlist.add(str.line[i])
  36.     end repeat
  37.     questions.addprop(x,qlist)
  38.     x=x+1
  39.     mem=member("question"&string(x))
  40.   end repeat
  41.   actoron(me)
  42. end
  43.  
  44. on next_question me
  45.   alarm=0
  46.   correct=[]
  47.   c=count(questions)
  48.   r=random(c)
  49.   qorder=getpropat(questions,r)
  50.   qlist=questions[r]
  51.   questions.deleteat(r)
  52.   sendallsprites(#new_q_graphic,"q"&string(qorder))
  53.   repeat with i=1 to (qlist.count)
  54.     qstring=qlist[i]
  55.     if qstring.char[1]="!" then
  56.       qstring=qstring.char[2..qstring.length]
  57.       correct.add(i)
  58.     end if
  59.     sendallsprites(#update_question,qorder)
  60.     sendallsprites(#answer_text,i,qstring)
  61.   end repeat
  62.   curnum=curnum+1
  63.   sendallsprites(#resume_answers)
  64.   sendallsprites(#current_num,curnum,totalnum)
  65. end
  66.  
  67. on answer_clicked me,n
  68.   sendallsprites(#pause_answers)
  69.   if correct.getpos(n)>0 then
  70.     cscore=cscore+1
  71.   end if
  72.   if questions.count=0 then
  73.     test_done(me)
  74.   else
  75.     alarm=the ticks+wait_amt
  76.     next_action="next_question(me)"
  77.   end if
  78.   if test="post" then
  79.     tloc=sendallsprites(#get_loc,correct[1])
  80.     x1=tloc[1]-30
  81.     y1=tloc[2]
  82.     sendallsprites(#move_arrow,point(x1,y1))
  83.   end if
  84. end
  85.  
  86. on stepframe me
  87.   if alarm>0 then
  88.     if the ticks>alarm then
  89.       do(next_action)
  90.     end if
  91.   end if
  92. end
  93.  
  94. on actoron me
  95.   g=getpos(the actorlist,me)
  96.   if g=0 then add(the actorlist,me)
  97. end
  98.  
  99. on actoroff me
  100.   g=getpos(the actorlist,me)
  101.   if g<>0 then deleteat(the actorlist,g)
  102. end
  103.  
  104. on test_done me
  105.   x=4
  106.   if test="pre" then 
  107.     next_action="show_score(me)"
  108.     alarm=the ticks+(member("Pre2").duration/11.0)
  109.     puppetsound 1,"Pre2"
  110.   end if
  111.   if test="post" then 
  112.     next_action="show_score(me)"
  113.     alarm=the ticks+(member("Post2").duration/11.0)
  114.     puppetsound 1,"Post2"
  115.   end if
  116. end
  117.  
  118. on show_score me
  119.   actoroff(me)
  120.   member("FinalScore").text=string(cscore)
  121.   go frame "score"
  122.   next_action=sendsprite(11,#blink_on)
  123.   if test="pre" then 
  124.     alarm=the ticks+member("Pre3").duration
  125.     puppetsound 1,"Pre3"
  126.     scores.pre=cscore
  127.   end if
  128.   if test="post" then 
  129.     alarm=the ticks+member("Post3").duration
  130.     puppetsound 1,"Post3"
  131.     scores.post=cscore
  132.     save_scores(me)
  133.   end if
  134.   sendallsprites(#set_tag,"score")
  135. end
  136.  
  137. on save_scores me
  138.   global ctrlobj
  139.   str=numtochar(13)&numtochar(10)&"-----------------"&numtochar(13)&numtochar(10)&"Name:"&ctrlobj.userinfo.fname&" "&ctrlobj.userinfo.lname&numtochar(13)&numtochar(10)&"Date/time:"&the date&" "&the time&numtochar(13)&numtochar(10)&"Address:"&ctrlobj.userinfo.address&numtochar(13)&numtochar(10)&"City/state:"&ctrlobj.userinfo.city&" "&ctrlobj.userinfo.state&" "&ctrlobj.userinfo.zip&numtochar(13)&numtochar(10)&"Pretest Score:"&string(scores.pre)&numtochar(13)&numtochar(10)&"Post Test:"&string(scores.post)&numtochar(13)&numtochar(10)
  140.   fname=basysfolder("desktop")&"wpscores.txt"
  141.   fobj=new(xtra "fileio")
  142.   if fileexists(fname)=0 then
  143.     fobj.openfile(fname,0)
  144.     str=readfile(fobj)&str
  145.   else
  146.     createfile(fobj,fname)
  147.     fobj.openfile(fname,0)
  148.   end if
  149.   setposition(fobj,0)
  150.   writestring(fobj,str)
  151.   closefile(fobj)
  152. end
  153.  
  154.  
  155.